package com.daguchuangyi.erp_android.productlist.imagetell.widget;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.daguchuangyi.erp_android.R;

/**
 * Created by lijianjian on 2018/3/14.
 */

public class ImageTellProgressDialog extends DialogFragment {

    private static final String TAG_TITLE = "TAG_TITLE";
    private String mTitle = "请耐心等待，系统正在识别图片";
    private TextView mTellHintTv;

    public static ImageTellProgressDialog getInstance(String title) {
        ImageTellProgressDialog dialog = new ImageTellProgressDialog();
        Bundle bundle = new Bundle();
        bundle.putString(TAG_TITLE, title);
        dialog.setArguments(bundle);
        return dialog;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mTitle = getArguments().getString(TAG_TITLE);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_image_tell_progress_layout, container, false);
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        TextView titleTv = view.findViewById(R.id.title_tv);
        titleTv.setText(mTitle);
        mTellHintTv = view.findViewById(R.id.tell_hint_tv);
        if (TextUtils.equals("请耐心等待，系统正在识别图片", mTitle)) {
            mTellHintTv.setVisibility(View.VISIBLE);
        } else {
            mTellHintTv.setVisibility(View.INVISIBLE);
        }
    }


    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.75), ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}
